//
//  YTNFDayView.m
//  yitaicaijing
//
//  Created by DIANGHONG on 2018/7/11.
//  Copyright © 2018年 DIANGHONG. All rights reserved.
//

#import "YTNFDayView.h"
@interface YTNFDayView ()
@property (weak, nonatomic) IBOutlet UILabel *dataLabel; // 日期
@property (weak, nonatomic) IBOutlet UILabel *weekLabel;   // 星期

@end
@implementation YTNFDayView

// 实例化方法
+ (instancetype)dayViewWithFrame:(CGRect)frame
{
    UINib *nib = [UINib nibWithNibName:@"YTNFDayView" bundle:nil];
    YTNFDayView *view = [nib instantiateWithOwner:nil options:nil][0];
    view.frame = frame;
   
    return view;
}

- (void)awakeFromNib
{
    [super awakeFromNib];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    [dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:8]];
    
    self.dataLabel.text = [dateFormatter stringFromDate:[NSDate date]];
    self.weekLabel.text = [self weekdayStringFromDate:[NSDate date]];
}




- (NSString*)weekdayStringFromDate:(NSDate*)inputDate {
    
    NSArray *weekdays = [NSArray arrayWithObjects: [NSNull null], @"星期天", @"星期一", @"星期二", @"星期三", @"星期四", @"星期五", @"星期六", nil];
    
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
    
    NSTimeZone *timeZone = [[NSTimeZone alloc] initWithName:@"Asia/SuZhou"];
    
    [calendar setTimeZone: timeZone];
    
    NSCalendarUnit calendarUnit = NSCalendarUnitWeekday;
    
    NSDateComponents *theComponents = [calendar components:calendarUnit fromDate:inputDate];
    
    return [weekdays objectAtIndex:theComponents.weekday];
    
}
@end
